package com.si.controller.web;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import com.si.entity.*;
import com.si.service.*;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.si.util.HTMLTag;
import com.si.util.Paging;
import com.si.util.QueryWhere;


/**
 * @author 蒋世维
 *
 * 项目名称：yishi
 * 类名称：IndexController
 * 类描述：登录验证
 * 创建人：jiangshiwei
 * 创建时间：2018-12-27 PM12:59:08
 * 修改备注：
 * @version  1.0.0
 */
@Controller
@RequestMapping("/index")
public class IndexController {

	@Autowired
	private BannerService bannerService;
	@Autowired
	private InfoService infoService;
	@Autowired
	private BrandActivityService brandActivityService;
	@Autowired
	private BannerTwoService bannerTwoService;

	@Autowired
	private BrandService brandService;
	@Autowired
	private BottomService bottomService;
	/**
	 *
	 * @return
	 */
	@RequestMapping
	public String load(ModelMap modelMap) {
		QueryWhere.remove();
		//banner
		List<Banner> bannerList = bannerService.getAll();
		modelMap.put("bannerList", bannerList);

		//banner1
		List<BannerTwo> bannertwo = bannerTwoService.getAll();
		modelMap.put("bannertwo", bannertwo);

		//品牌图片+连接
		List<Brand> brand = brandService.getAll();
		modelMap.put("brand", brand);

		//品牌图片+连接
		List<Bottom> bottomList = bottomService.getAll();
		modelMap.put("bottomList", bottomList);

		//品种推介
		QueryWhere.setOrderList(Order.desc("createDate"));
		Paging<BrandActivity> brandPaging = brandActivityService.createCriteriaPaging(0, 6);
		modelMap.put("brandList", brandPaging.getData());
		//新闻资讯
		QueryWhere.remove();
		QueryWhere.push(Restrictions.eq("infoTypeClassA.id",1));
		QueryWhere.setOrderList(Order.desc("createDate"));
		Paging<Info> newPaging = infoService.createCriteriaPaging(0, 11);
		modelMap.put("newList", newPaging.getData());
		//政策解读
		QueryWhere.remove();
		QueryWhere.push(Restrictions.eq("infoTypeClassA.id",2));
		QueryWhere.setOrderList(Order.desc("createDate"));
		Paging<Info> jieduPaging = infoService.createCriteriaPaging(0, 10);
		modelMap.put("jieduList", jieduPaging.getData());
		//通知公告
		QueryWhere.remove();
		QueryWhere.push(Restrictions.eq("infoTypeClassA.id",3));
		QueryWhere.setOrderList(Order.desc("createDate"));
		Paging<Info> gonggaoPaging = infoService.createCriteriaPaging(0, 10);
		modelMap.put("gonggaoList", gonggaoPaging.getData());

		//品种成果
		QueryWhere.remove();
		QueryWhere.push(Restrictions.eq("infoTypeClassA.id",5));
		QueryWhere.setOrderList(Order.desc("createDate"));
		Paging<Info> chengguoPaging = infoService.createCriteriaPaging(0, 6);
		modelMap.put("chengguoList", chengguoPaging.getData());
		return "webPage/index";
	}

	/**
	 *
	 * @return
	 */
	@RequestMapping(value="other")
	public String other(ModelMap modelMap) {
		//创新团队
		QueryWhere.push(Restrictions.eq("infoTypeClassA.id",7));
		QueryWhere.setOrderList(Order.desc("createDate"));
		Paging<Info> innovatePaging = infoService.createCriteriaPaging(0, 14);
		modelMap.put("innovateList", innovatePaging.getData());
		//专利成果
		QueryWhere.push(Restrictions.eq("infoTypeClassA.id",4));
		QueryWhere.setOrderList(Order.desc("createDate"));
		Paging<Info> achievementsPaging = infoService.createCriteriaPaging(0, 14);
		modelMap.put("achievementsList", achievementsPaging.getData());
		return "webPage/other";
	}
	/**
	 *
	 * @return
	 */
	@RequestMapping(value="right")
	public String right(ModelMap modelMap,HttpServletRequest request) {
		//专利成果
		QueryWhere.push(Restrictions.eq("infoTypeClassA.id",4));
		QueryWhere.setOrderList(Order.desc("createDate"));
		Paging<Info> achievementsPaging = infoService.createCriteriaPaging(0, 5);
		for (Info info:achievementsPaging.getData()) {
			info.setCnContent(HTMLTag.delHTMLTag(info.getCnContent()));
		}
		modelMap.put("achievementsList", achievementsPaging.getData());

		//专利成果
		QueryWhere.push(Restrictions.eq("infoTypeClassA.id",6));
		QueryWhere.setOrderList(Order.desc("createDate"));
		Paging<Info> conversionPaging = infoService.createCriteriaPaging(0, 5);
		for (Info info:conversionPaging.getData()) {
			info.setCnContent(HTMLTag.delHTMLTag(info.getCnContent()));
		}
		modelMap.put("conversionList", conversionPaging.getData());

		//政策法规
		QueryWhere.push(Restrictions.eq("infoTypeClassA.id",6));
		QueryWhere.setOrderList(Order.desc("createDate"));
		Paging<Info> regulationsPaging = infoService.createCriteriaPaging(0, 5);
		for (Info info:regulationsPaging.getData()) {
			info.setCnContent(HTMLTag.delHTMLTag(info.getCnContent()));
		}
		modelMap.put("regulationsList", regulationsPaging.getData());
		return "webPage/right";
	}
}
